package com.longsun.activity;

import com.example.longsun.R;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

public class SettingsActivity extends PreferenceActivity  implements OnSharedPreferenceChangeListener{
	Context context = null;
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        // Load the preferences from an XML resource
        addPreferencesFromResource(R.layout.settings);
        
        SharedPreferences sp = getPreferenceScreen().getSharedPreferences();  
        findPreference("etFundShare1").setSummary(sp.getString("etFundShare1", "500000.0"));
        findPreference("etFundShare2").setSummary(sp.getString("etFundShare2", "500000.0"));
        findPreference("etFundNet1").setSummary(sp.getString("etFundNet1", "1.0"));
        findPreference("etFundNet2").setSummary(sp.getString("etFundNet2", "1.0"));
    }
    
  @Override  
  protected void onResume() {  
      super.onResume();  
      getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener( this );  
  }  
    
  @Override  
  protected void onPause() {  
      super.onPause();  
      getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener( this );  
  }  
    
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) {  
      Preference pref = findPreference(key);  
      if (pref instanceof EditTextPreference) {  
          EditTextPreference etp = (EditTextPreference) pref;  
          pref.setSummary(etp.getText());  
      }  
  } 
}